package edu.whut.Test;

import edu.whut.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

/*
创建存储学生类的集合，遍历他,展示年龄低于18的
 */
public class test02 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第"+(i+1)+"个学生信息");
            addStudent(list);
        }


        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println(student.getName()+student.getAge());
        }

    }

    private static void addStudent(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = sc.nextLine();
        System.out.println("请输入年龄：");
        int age = sc.nextInt();
        Student stu = new Student(name,age);
        list.add(stu);
    }
}
